package cn.jljiayu.generator;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;

/**
 * @author zhangxiansheng
 */
public class MyBatisPlusCodeGenerator {


    public static void main(String[] args) {
        String projectPath = System.getProperty("user.dir");
        String outputDir = projectPath + "/oauth2-manage-client/src/main/java";

        FastAutoGenerator.create("jdbc:mysql://localhost:3306/oauth_sso?useUnicode=true&useSSL=false&characterEncoding=utf8",
                        "root",
                        "12345678")
                .globalConfig(builder -> {
                    builder.author("zhangbaoyu") // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .dateType(DateType.ONLY_DATE)
                            .commentDate("yyyy-MM-dd")
                            .outputDir(outputDir); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("cn.jljiayu.business.sys.client") // 设置父包名
                            .moduleName("repo") // 设置父包模块名
                            .entity("model")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .xml("mapping")
                            .controller("controller"); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("oauth2_registered_client") // 设置需要生成的表名
                            .addTablePrefix("t_", "c_")
                    .entityBuilder().enableLombok().addTableFills(
                            new Column("create_time", FieldFill.INSERT)
                    ).idType(IdType.ASSIGN_ID); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }

}
